package ae.pcfc.cldos.online.common.clddb.dao.provider;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import ae.pcfc.cldos.online.common.clddb.dao.FnpServiceMasterDAO;
import ae.pcfc.cldos.online.common.clddb.domain.FnpServiceMaster;
import ae.pcfc.cldos.online.common.dao.GenericDAO;

@Repository
public class FnpServiceMasterDAOImpl extends GenericDAO implements FnpServiceMasterDAO{

	@SuppressWarnings("unchecked")
	public List<FnpServiceMaster> getFnpCodeByServiceCode(Long serviceCode){
			DetachedCriteria criteria = DetachedCriteria.forClass(FnpServiceMaster.class);
			criteria.add(Restrictions.eq(FnpServiceMaster.__FNP_SERVICE_CODE, serviceCode));
			return (List<FnpServiceMaster>)getListByCriteria(criteria);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getFnpCodeListByServiceCode(Long serviceCode){
			DetachedCriteria criteria = DetachedCriteria.forClass(FnpServiceMaster.class);
			criteria.add(Restrictions.eq(FnpServiceMaster.__FNP_SERVICE_CODE, serviceCode));
			criteria.setProjection(Projections.property(FnpServiceMaster.__FNP_CODE));
			return (List<String>)getListByCriteria(criteria);
	}
	/**
	 * @param fnpServiceMaster
	 */
	public void add(FnpServiceMaster fnpServiceMaster){
		saveOrUpdate(fnpServiceMaster);
	}
	/**
	 * @param fnpServiceMasters
	 */
	public void insertAll(List<FnpServiceMaster> fnpServiceMasters,Long serviceCode){
		deleteAll(getFnpCodeByServiceCode(serviceCode));
		for(FnpServiceMaster fnpServiceMaster :fnpServiceMasters){
			add(fnpServiceMaster);
		}
	}

}
